<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="base::header">
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style type="text/css">
    body {
        background-image: url(/asynctask/images/bg.jpg);
        background-color: #000000;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        display: flex;
        display: -webkit-flex;
        align-items: center;
        justify-content: center;
    }

    #box {
        text-align: center;
        background-color: #dee4ed;
        padding: 40px;
    }

    h2 {
        margin-bottom: 15px;
    }
</style>
<body>
<div id="box">
    <h2>欢迎登录Layui</h2>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" name="account" lay-verify="required" autocomplete="off" placeholder="账号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required" autocomplete="off" placeholder="密码"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="login_button_id">登录</button>
            </div>
        </div>
    </form>
</div>
<script th:src="@{/js/md5.min.js}"></script>
<script>
    layui.use(['form', 'exbase'], function () {
        var form = layui.form, exbase = layui.exbase, $ = layui.$;
        form.on('submit(login_button_id)', function (data) {
            console.log("测试"+ctxPath)
            var submit_data = JSON.stringify({
                account: data.field.account,
                password: md5(data.field.password)
            });
            $.ajax({
                contentType: 'application/json',
                url: ctxPath + '/login',
                method: 'POST',
                data: submit_data,
                success: function (data) {
                    if (data.errorCode == exbase.AJAX_SUCCESS_CODE) {
                        window.location.href = contextPath + "/"
                    } else {
                        layer.msg(data.errorMsg, {icon: 2})
                    }
                }
            })
            return false;
        })
    })
</script>
</body>
</html>